import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Enumeration;

@WebServlet("/showRequest")
public class ShowRequestServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        StringBuilder sb=new StringBuilder();
        sb.append(req.getProtocol());
        sb.append("\n");
        sb.append(req.getMethod());
        sb.append("\n");
        sb.append(req.getRequestURI());
        sb.append("\n");
        sb.append(req.getContextPath());
        sb.append("\n");
        sb.append(req.getQueryString());
        sb.append("\n");
        //  把请求的header拼进来
        Enumeration<String>headerNames=req.getHeaderNames();
        while(headerNames.hasMoreElements()){
            String s = headerNames.nextElement();
            String value=req.getHeader(s);
            sb.append(s+": "+value);
            sb.append("\n");
        }
        resp.getWriter().write(sb.toString());

    }
}
